<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>会员签到赠送商品管理</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" href="js/dropzone/min/basic.min.css" />
    <link rel="stylesheet" href="js/dropzone/min/dropzone.min.css" />
</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header"><h4>签到赠送</h4>
                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>会员名称:</label>
                                <input type="text" class="form-control" name="nickName">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="editBtn">发货</button>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="card-body">

                    <table id="handsel_data"></table>

                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">签到赠送管理</h4>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm" action="" method="post" data-target="validator">
                        <input type="hidden" name="memberId">
                        <div class="form-group">
                            <label for="commodityName" class="control-label">商品名称：</label>
                            <input type="text" class="form-control" id="commodityName" name="commodityName" required>
                        </div>
                        <div class="form-group">
                            <label for="number" class="control-label">商品数量：</label>
                            <input type="text" class="form-control" id="number" name="number" onkeyup="zhzs(this)" required>
                        </div>
                        <div class="form-group">
                            <label class="control-label">详细地址：</label>
                            <textarea class="form-control" id="address" rows="2" name="address" ></textarea>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="sava">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
    <!-- jquery-form表单提交插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <!--消除数字以外的字符插件-->
    <script type="text/javascript" src="js/inputmoney.js"></script>

    <script type="text/javascript">

        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'memberId',title: '会员ID',visible:false},
            {field: 'nickName',title: '会员名称'},
            {field: 'commodityName',title: '商品名称'},
            {field: 'number',title: '商品数量',formatter:function (value) {
                    if (value==0){
                        return "无";
                    }else {
                        return value;
                    }
                }},
            {field: 'address',title: '详细地址',formatter:function (value) {
                    if (value==null){
                        return "无";
                    }else {
                        return value;
                    }
                }},
            {field: 'state',title: '状态',formatter:function (value) {
                    console.log(value);
                    if (value == '0'){
                        return "<button class=\"btn btn-primary btn-sm\">未&nbsp;发&nbsp;货</button>";
                    }else {
                        return "<button class=\"btn btn-success btn-sm\">已&nbsp;发&nbsp;货</button>";
                    }
                }},
            {field: 'operator',title: '操作人',formatter:function (value) {
                    if (value==null){
                        return "无";
                    }else {
                        return value;
                    }
                }},
            {field: 'operationTime',title: '操作时间',formatter:function (value) {
                    if (value==null){
                       return "无";
                    }else {
                        return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                    }
                }}

        ];

        //进入主界面加载数据
        zero2one.datagrid("handsel_data", "/remote/signinHandsel/list",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
        }, columns);

        //点击查询按钮重新加载页面数据
        $("#searchFormBtn").click(function () {
            $('#handsel_data').bootstrapTable('refresh');
        });


        //点击编辑按钮弹出模态框
        $("#editBtn").click(function () {
            //获取选中行的数据
            var datas = $('#handsel_data').bootstrapTable('getSelections');
            console.log(datas);
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1){
                //填充表单
                $("#addOrEditForm").formloader({data: datas[0]});
            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
                return;
            }
            $("#addOrEditModal").modal("show");
        });

        //保存按钮的点击事件
        $("#sava").click(function () {
            zero2one.request("/remote/signinHandsel/editShipping",$("#addOrEditForm").serialize(),function (data) {
                if (data.success) {
                    window.location.reload();
                }else {
                    $.messager.alert("温馨提示", data.msg)
                }
            });
        });

    </script>

</div>
</body>
</html>
